from django.db import models
from django.shortcuts import reverse
from django.utils.translation import gettext_lazy as _
from .project import Project

from .lib import ProjectSubMixin

class EthicalReview(ProjectSubMixin, models.Model):
    project = models.ForeignKey(
        verbose_name=_("项目"),
        to=Project,
        on_delete=models.CASCADE,
    )

    time = models.DateField(
        verbose_name=_("创建时间"),
        auto_now_add=True
    )
    
    approval_projcet_time = models.DateField(
        verbose_name=_('伦理立项时间'),
        null=True,
        blank=True,
        default=None
    )

    approval_time = models.DateField(
        verbose_name=_('伦理批件时间'),
        null=True,
        blank=True,
        default=None
    )

    eafpsd = models.DateField(
        verbose_name=_('伦理申请首次提交日期'),
        null=True,
        blank=True,
        default=None
    )

    eaftbad = models.DateField(
        verbose_name=_('伦理申请首次获批日期'),
        null=True,
        blank=True,
        default=None
    )

    # TODO
    version_number = models.CharField(
        verbose_name=_('伦理批准资料版本号'),
        help_text=_('需要提供方案和ICF的编号、版本号、版本日期'),
        max_length=2048,
        blank=True,
        default=''
    )

    ethical_approval_num = models.DateField(
        verbose_name=_('伦理批件号'),
        help_text=_('批准日期'),
        null=True,
        blank=True,
        default=None
    )


    note = models.TextField(
        verbose_name=_('备注'),
        blank=True,
        default=''
    )


    class Meta:
        default_permissions = []
        db_table="project_ethical_review"
        verbose_name=_("项目伦理审核")
        verbose_name_plural= verbose_name

    @classmethod
    def get_link(cls, project_id, id):
        return reverse("project:ethical_review/detail", kwargs={'project_pk': project_id, 'pk': id})

